#! /bin/sh

mkdir -p out || exit 99

name=$( basename "$0" )
datafile="$srcdir/${name}.data"
dumpfile="out/${name}.dump"
resultfile="out/${name}.result"
expectfile="$srcdir/${name}.expect"

./mkelf "$dumpfile" <<EOF
ei_class = 1
ei_data = 1
e_machine = 3
e_phoff = 0x1000
e_phentsize = 32

DATA = $datafile
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Cannot create ELF file" >&2
    exit $rc
fi
echo "Created ELF dump: $dumpfile"

./checkattr "$dumpfile" <<EOF
file = directory:
file.set.number = number:1
file.set.0 = directory:
file.set.0.fd = number
file.format = string: elf

cpu = directory:
cpu.number = number:1
cpu.0 = directory:
cpu.0.PRSTATUS = blob:\
0300000004000000050000000b000000\
70656e64686f6c645f70696470706964\
706772705f73696470725f7574696d65\
70725f7374696d6570725f637574696d\
70725f637374696d2065627820656378\
20656478206573692065646920656270\
20656178202064732020657320206673\
202067736f7269672065697020206373\
65666c612065737020207373
cpu.0.reg = directory:
cpu.0.reg.ebx = number:0x78626520
cpu.0.reg.ecx = number:0x78636520
cpu.0.reg.edx = number:0x78646520
cpu.0.reg.esi = number:0x69736520
cpu.0.reg.edi = number:0x69646520
cpu.0.reg.ebp = number:0x70626520
cpu.0.reg.eax = number:0x78616520
cpu.0.reg.ds = number:0x73642020
cpu.0.reg.es = number:0x73652020
cpu.0.reg.fs = number:0x73662020
cpu.0.reg.gs = number:0x73672020
cpu.0.reg.orig_eax = number:0x6769726f
cpu.0.reg.eip = number:0x70696520
cpu.0.reg.cs = number:0x73632020
cpu.0.reg.eflags = number:0x616c6665
cpu.0.reg.esp = number:0x70736520
cpu.0.reg.ss = number:0x73732020
cpu.0.pid = number:0x6469705f
EOF
rc=$?
if [ $rc -ne 0 ]; then
    echo "Attribute check failed" >&2
    exit $rc
fi

exit 0
